/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package swing.formularios;

import hibernate.entidades.DetallePedCli;
import hibernate.entidades.PedidoCliente;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import swing.modelos.ModeloDetallesPedidoCliente;

/**
 *
 * @author ariel
 */
public class FormDetalles extends javax.swing.JDialog {

    private final PedidoCliente pedido;

    /**
     * Creates new form FormDetalles
     */
    public FormDetalles(PedidoCliente pedido, java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        this.pedido = pedido;
        initComponents();
        campoCodigo.setText(pedido.getCodPedCli().toString());
        campoEmpleado.setText(pedido.getCodTrab().getCodTrab());
        campoCliente.setText(pedido.getDni().getDni());
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
        campoFecha.setText(sdf.format(pedido.getFecha()));
        areaObservaciones.setText(pedido.getObservaciones());
        campoFPago.setText(pedido.getFPago());

        ModeloDetallesPedidoCliente modeloDetalles = new ModeloDetallesPedidoCliente();
        List<DetallePedCli> detalles = pedido.getDetallePedCliList();
        ArrayList<DetallePedCli> detalles_array = new ArrayList();
        detalles_array.addAll(detalles);
        modeloDetalles.setDetalles(detalles_array);
        jTable1.setModel(modeloDetalles);

        campoSubtotal.setText(String.valueOf(red(modeloDetalles.getTotal())));
        campoDescuento.setText(String.valueOf(red(modeloDetalles.getTotal() * pedido.getDescuento() / 100)));
        campoTotal.setText(String.valueOf(red(pedido.getTotal())));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        etiquetaTituloDetalles = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        etiquetaEmpleado = new javax.swing.JLabel();
        etiquetaCliente = new javax.swing.JLabel();
        etiquetaFecha = new javax.swing.JLabel();
        etiquetaCodigo = new javax.swing.JLabel();
        campoCodigo = new javax.swing.JLabel();
        campoEmpleado = new javax.swing.JLabel();
        campoCliente = new javax.swing.JLabel();
        campoFecha = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        areaObservaciones = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        campoTotal = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        campoSubtotal = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        campoDescuento = new javax.swing.JTextField();
        etiquetaFPago = new javax.swing.JLabel();
        campoFPago = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        etiquetaTituloDetalles.setFont(new java.awt.Font("Trajan Pro", 0, 24)); // NOI18N
        etiquetaTituloDetalles.setForeground(new java.awt.Color(153, 51, 0));
        etiquetaTituloDetalles.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("swing/formularios/Bundle"); // NOI18N
        etiquetaTituloDetalles.setText(bundle.getString("NUEVO CLIENTE")); // NOI18N

        jScrollPane1.setViewportView(jTable1);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/accepted.png"))); // NOI18N
        jButton1.setText(bundle.getString("FormDetalles.jButton1.text")); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        etiquetaEmpleado.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        etiquetaEmpleado.setText(bundle.getString("FormDetalles.etiquetaEmpleado.text")); // NOI18N

        etiquetaCliente.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        etiquetaCliente.setText(bundle.getString("FormDetalles.etiquetaCliente.text")); // NOI18N

        etiquetaFecha.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        etiquetaFecha.setText(bundle.getString("FormDetalles.etiquetaFecha.text")); // NOI18N

        etiquetaCodigo.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        etiquetaCodigo.setText(bundle.getString("FormDetalles.etiquetaCodigo.text")); // NOI18N

        campoCodigo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        campoEmpleado.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        campoCliente.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        campoFecha.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/printer.png"))); // NOI18N
        jButton2.setText(bundle.getString("FormDetalles.jButton2.text")); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        areaObservaciones.setEditable(false);
        areaObservaciones.setBackground(new java.awt.Color(243, 243, 243));
        areaObservaciones.setColumns(20);
        areaObservaciones.setRows(5);
        jScrollPane2.setViewportView(areaObservaciones);

        jLabel1.setText(bundle.getString("FormDetalles.jLabel1.text")); // NOI18N

        campoTotal.setEditable(false);
        campoTotal.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        campoTotal.setText(bundle.getString("FormDetalles.campoTotal.text")); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel2.setText(bundle.getString("FormDetalles.jLabel2.text")); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel3.setText(bundle.getString("FormDetalles.jLabel3.text")); // NOI18N

        campoSubtotal.setEditable(false);
        campoSubtotal.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        campoSubtotal.setText(bundle.getString("FormDetalles.campoSubtotal.text")); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel4.setText(bundle.getString("FormDetalles.jLabel4.text")); // NOI18N

        campoDescuento.setEditable(false);
        campoDescuento.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        campoDescuento.setText(bundle.getString("FormDetalles.campoDescuento.text")); // NOI18N

        etiquetaFPago.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        etiquetaFPago.setText(bundle.getString("FormDetalles.etiquetaFPago.text")); // NOI18N

        campoFPago.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(etiquetaTituloDetalles, javax.swing.GroupLayout.DEFAULT_SIZE, 660, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.CENTER)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(etiquetaCliente)
                                            .addComponent(etiquetaCodigo)
                                            .addComponent(etiquetaEmpleado)
                                            .addComponent(etiquetaFecha))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(campoCodigo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(campoEmpleado, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(campoCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(campoFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(etiquetaFPago)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(campoFPago, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane2)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel1)
                                        .addGap(0, 0, Short.MAX_VALUE))))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 29, Short.MAX_VALUE)
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoSubtotal, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 440, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoDescuento, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(183, 183, 183)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(etiquetaTituloDetalles, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(etiquetaCodigo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(campoCodigo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(etiquetaEmpleado, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(campoEmpleado, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(etiquetaCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(campoCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(etiquetaFecha, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(campoFecha, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(etiquetaFPago, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(campoFPago, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(2, 2, 2))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(campoSubtotal, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoDescuento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addGap(23, 23, 23))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-676)/2, (screenSize.height-693)/2, 676, 693);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(this, "Aún no implementado", "Error", JOptionPane.OK_OPTION);
    }//GEN-LAST:event_jButton2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea areaObservaciones;
    private javax.swing.JLabel campoCliente;
    private javax.swing.JLabel campoCodigo;
    private javax.swing.JTextField campoDescuento;
    private javax.swing.JLabel campoEmpleado;
    private javax.swing.JLabel campoFPago;
    private javax.swing.JLabel campoFecha;
    private javax.swing.JTextField campoSubtotal;
    private javax.swing.JTextField campoTotal;
    private javax.swing.JLabel etiquetaCliente;
    private javax.swing.JLabel etiquetaCodigo;
    private javax.swing.JLabel etiquetaEmpleado;
    private javax.swing.JLabel etiquetaFPago;
    private javax.swing.JLabel etiquetaFecha;
    private javax.swing.JLabel etiquetaTituloDetalles;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
    public double red(double numero) {

        return Math.rint(numero * 100) / 100;

    }
}
